<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue 示例</title>
</head>
<body>
    <div id="app">
        <!-- 此处用计算属性可以用到缓存，而使用method时每次页面刷新要重新调用 -->
        姓名：{{fullName}}
    </div>

    <script src="http://unpkg.com/vue/dist/vue.min.js"></script>
    <script>
        // 变量app表示一个vue实例
        var app = new Vue({
            el: '#app', //用于指定一个页面中存在的Dom元素来挂载Vue示例。挂载成功后可以使用app.$el来访问该元素
            data: {
                firstName: 'Jack',
                lastName: 'Green'
            },
            computed: {
                fullName: {
                    //getter,用户读取
                    get:function(){
                        return this.firstName + ' ' + this.lastName;
                    },
                    //setter，写入时触发
                    set: function(newValue){
                        var names = newValue.split(' ');
                        this.firstName = names[0];
                        this.lastName = names[names.lenght - 1];
                    }
                }
            }
        })
    </script>
</body>
</html>